<template>
  <div class="header">

    <div class="header-return" v-show="showHeader">
      <span class="border-return"></span>
      <span class="iconfont return" @click="toHome"> &#xe672;</span>
    </div>

    <div class="header-top" v-show="!showHeader" :style="styleOpacity">
      <div class="header-left">
        <span class="iconfont" @click="toHome">
          &#xe672;
        </span>
      </div>
      金海湖风景区
    </div>

  </div>
</template>

<script>
export default {
  name: "headers",
  data(){
    return{
      showHeader:true,
      styleOpacity:{
        opacity:0
      }
    }
  },
  methods:{
    toHome(){
      this.$router.push('/')
    }
  },
  mounted() {
    let This = this
    window.addEventListener("scroll", function () {
      let top = document.documentElement.scrollTop;
      if (top > 20){
        let opacity = top/130
        opacity = opacity > 1 ? 1:opacity
        This.styleOpacity = {opacity}
        This.showHeader = false
      }else {
        This.showHeader = true
      }
    })
  }
}
</script>

<style scoped>
  .header-return{
    position: absolute;
    left: .1rem;
    top: .1rem;
    width: .72rem;
    height: .72rem;
  }
  .border-return{
    display: block;
    background: #000;
    width: .72rem;
    height: .72rem;
    opacity: .5;
    border-radius: .36rem;
  }
  .return{
    position: absolute;
    right: 4px;
    top: .2rem;
    color: #fff;
    width: .72rem;
    height: .72rem;
    text-align: left;
    text-indent: .24rem;
    font-size: .32rem;
    font-weight: bold;
  }
  .header-top{
    position: fixed;
    top: 0;
    text-align: center;
    width: 100%;
    line-height: .88rem;
    background: #00bcd4;
    color: #fff;
    font-size: .35rem;
  }
  .header-left{
    position: absolute;
    width: .4rem;
    padding: 0 .2rem;
    text-align: center;
    font-weight: bold;
  }
</style>
